<template>
  <div id="home">
    <el-container>
      <el-header class="homeHeader">
        <div class="title">云e办</div>
        <div>
          <el-button icon="el-icon-bell" type="text" @click="$router.push('/chat')"
                     class="tw-text-yellow-300 tw-mr-3 chatButton tw-text-xl">
          </el-button>
          <el-dropdown class="userInfo" @command="handleCommand">
          <span class="el-dropdown-link">
            <span v-text="user.name"></span>
            <img :src="user.userFace">
          </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="adminInfo">个人中心</el-dropdown-item>
              <el-dropdown-item command="setting">设置</el-dropdown-item>
              <el-dropdown-item command="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu router>
            <el-submenu :index="index.toString()" v-for="(item,index) in routers" :key="index" v-if="!item.hidden">
              <template slot="title">
                <i :class="item.iconCls" style="color: #9379e2;margin-right: 10px"></i>
                <span>{{ item.name }}</span>
              </template>
              <el-menu-item-group :index="item.path" v-for="(children,index2) in item.children" :key="index2">
                <el-menu-item :index="children.path">{{ children.name }}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path!='/home'"
                         style="margin-bottom: 10px">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ this.$router.currentRoute.name }}</el-breadcrumb-item>
          </el-breadcrumb>
          <div class="homeWelcome" v-if="this.$router.currentRoute.path=='/home'">
            <span>欢迎来到云e办</span><br>
            <img src="../assets/welcome.png" width="400px" height="400px">
          </div>
          <router-view class="homeRouterView"/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: "Home",
  data() {
    return {
      // user: {},
    }
  },
  computed: {
    routers() {
      return this.$store.state.routers
    },
    ...mapState({
      user: state => state.currentAdmin
    })
  },
  methods: {
    handleCommand(command) {
      if (command === "logout") {
        this.commonUtil.logout()
      } else if (command === 'adminInfo') {
        this.$router.push('/adminInfo')
      }
    }
  }
}
</script>

<style scoped>
.chatButton:focus {
  display: none;
}

.homeHeader {
  background: #409eff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  box-sizing: border-box;
}

.homeHeader .title {
  font-size: 30px;
  font-family: "Adobe 仿宋 Std R";
  letter-spacing: 3px;
  display: inline-block;
  font-weight: bold;
  color: #def;
  text-shadow: 0 0 1px currentColor, -1px -1px 1px #000, 0 -1px 1px #000, 1px -1px 1px #000, 1px 0 1px #000, 1px 1px 1px #000, 0 1px 1px #000, -1px 1px 1px #000, -1px 0 1px #000;
  -webkit-filter: url(#diff1);
  filter: url(#diff1);
}

.homeHeader .userInfo {
  cursor: pointer;
}

.el-dropdown-link img {
  width: 48px;
  height: 48px;
  border-radius: 24px;
  margin-left: 7px;
}

.homeWelcome {
  font-size: 20px;
  font-family: "Adobe 仿宋 Std R";
  letter-spacing: 13px;
  color: #8cb2e2;
  text-shadow: 0 0 1px currentColor, -1px -1px 1px #000, 0 -1px 1px #000, 1px -1px 1px #000, 1px 0 1px #000, 1px 1px 1px #000, 0 1px 1px #000, -1px 1px 1px #000, -1px 0 1px #000;
  -webkit-filter: url(#diff1);
  filter: url(#diff1);
}

.el-dropdown-link {
  display: flex;
  align-items: center;
  color: white;
}
</style>